home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6217 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: news.iadfw.net!usenet
  2. From: alpet@airmail.net (Adam Peterson)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: HELP: UNIX's directory functions.
  5. Date: Fri, 23 Feb 1996 03:55:08 GMT
  6. Organization: customer of Internet America
  7. Message-ID: <4gj6ug$o0h@news-f.iadfw.net>
  8. References: <Pine.ULT.3.91.960217002153.21669B-100000@hertz.njit.edu> <824598921snz@genesis.demon.co.uk> <4gigogINN8nq@keats.ugrad.cs.ubc.ca>
  9. NNTP-Posting-Host: dal24-12.ppp.iadfw.net
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku) wrote:
  13.  
  14. >In article <824598921snz@genesis.demon.co.uk>,
  15. >Lawrence Kirby  <fred@genesis.demon.co.uk> wrote:
  16. > >In article <Pine.ULT.3.91.960217002153.21669B-100000@hertz.njit.edu>
  17. > >           dxp8108@hertz.njit.edu "Dharmesh Patel" writes:
  18. > >
  19. > >>
  20. > >>Hi all!
  21. > >>
  22. > >>I need help with couple of things in C.  I need to know how the functions 
  23. > >>opendir, readdir, closedir, and rewinddir work.  I also need to know the 
  24. > >>elements of the struct dirent.
  25. > >
  26. > >Unfortunately these are not defined in C. 
  27. > >
  28. > >>The reason for this request is that I have to write a program that 
  29. > >>simulates the unix command 'pwd', the hard way.
  30. > >
  31. > >They are Unix/POSIX defined functions and the place to ask about them
  32. > >is comp.unix.programmer.
  33.  
  34. >...and I might add that the revered "K&R" book does cover the basic UNIX
  35. >programming interface, including directory functions, stat() and other goodies.
  36.  
  37. >It sounds like you don't have this book. Shame! :)
  38.  
  39. To answer the original question, Unix treats directories like files,
  40. thus the open, read, close, rewind functions.  To process a list of
  41. files do something like this:
  42.  
  43. if opendir succeeds
  44. {
  45.   while not eof dir
  46.     readdir
  47.   closedir
  48. }
  49.  
  50. It's been a while since i've done Unix, but thats basically it...
  51.  
  52. Adam
  53.  
  54.  
  55.  
  56.  
  57.